<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:MASCPolicyAssertions="http:///schemas/MASCPolicyAssertions/_cfxCsPYBEdy-l5FUdqpG8Q/0" 
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" 
    xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" 
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes= "uml xmi ecore MASCPolicyAssertions"
    version="2.0">   

    <xsl:output  method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
     
    <xsl:template match="xmi:XMI[@xmi:version='2.1']">                                                                              
        <xsl:comment> 
            Example 2 of GoalPolicyAssertion schema (and others) in WS-Policy4MASC version 0.8     This example is for the Canadian Weather Report example.
            The only Web service operation is: Integer weather(String postalCode).
            This example is for the output message - the policy must be attached to this message. 
        </xsl:comment>                               
        
        <xsl:text disable-output-escaping="yes">    
            <![CDATA[ <wsp:Policy 
                xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:masc-gp="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-gp"
                xmlns:masc-se="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-se"
                xmlns:masc-ex="http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ex" xmlns:mascom="
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-om" xmlns:mascsc="
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-sc" xmlns:mascap="
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ap"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://schemas.xmlsoap.org/ws/2004/09/policy C:\workspace\WS-Policy4MASCv0-
                8\Schemas\ws-policy.xsd http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-gp C:\workspace\WSPolicy4MASCv0-8\Schemas\ws-policy4masc-gp.xsd
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-se C:\workspace\WS-Policy4MASCv0-8\Schemas\wspolicy4masc-se.xsd
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ex C:\workspace\WS-Policy4MASCv0-8\Schemas\wspolicy4masc-ex.xsd
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-om C:\workspace\WS-Policy4MASCv0-8\Schemas\wspolicy4masc-sc.xsd
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-sc C:\workspace\WS-Policy4MASCv0-8\Schemas\wspolicy4masc-om.xsd
                http://www.sce.unsw.edu.au/~vtosic/ws-policy4masc/masc-ap C:\workspace\WS-Policy4MASCv0-8\Schemas\wspolicy4masc-ap.xsd"
                targetNamespace="TARGETmasc-gp-Example2" xmlns:tns="masc-gp-Example2"
                xmlns:wsdlfile="C:\workspace\WS-Policy4MASCv0-8\Examples\WSDL-Example2.xml"
                xmlns:ontology1="C:\workspace\WS-Policy4MASCv0-8\Examples\Ontology-Example2.xml">]]> 
        </xsl:text> 
 
        <xsl:comment> 
            DEFINITION OF STATES    
        </xsl:comment>                               
         <xsl:text disable-output-escaping="yes"> <![CDATA[ <masc-se:StateDefinition MASCID="Executing"/> ]]> </xsl:text>
        
        <xsl:apply-templates/>
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[</wsp:Policy>]]> &#10;</xsl:text>
    </xsl:template>
    
    <!--  *********** GOAL POLICY ASSERTION ********* -->
    <xsl:template match="MASCPolicyAssertions:GoalpolicyAssertion" >                   
        
        <xsl:comment> 
            DEFINITION OF EVENTS    
        </xsl:comment>                                       
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ <masc-se:EventDefinition MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"> "/> &#10; </xsl:text>                        
        
        <xsl:comment> 
            DEFINITION OF WHEN CONSTRUCTS   
        </xsl:comment>                                       
        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-se:When MASCID="Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA["> ]]> &#10; </xsl:text>  
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:AllowedSates> ]]> &#10;</xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:SateRefTo="tns:Executing"/> ]]> &#10; </xsl:text>         
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:AllowedSates>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:EventRefTo="tns:]]></xsl:text><xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[</masc-se:When> ]]> &#10; </xsl:text>
        
        <xsl:comment> 
            DEFINITION OF BOOLEAN EXPRESSIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes">&#10; <![CDATA[ <masc-ex:BooleanExpression MASCID= "]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _BE"/> &#10;</xsl:text>  
        <xsl:value-of disable-output-escaping="yes" select="//MASCPolicyAssertions:GoalpolicyAssertion/@BooleanExpression"/>  
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ </masc-ex:BooleanExpression> ]]> &#10; </xsl:text> 
        
        <xsl:comment> 
            DEFINITION OF GOAL POLICY ASSERTIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-gp:GoalPolicyAssertion MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text> 
        <xsl:text disable-output-escaping="yes"> <![CDATA[ ResponsibleParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@ResponsibleParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ ManagementParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@ManagementParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ IsActiveResponsibleParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@IsActive"/> <xsl:text disable-output-escaping="yes"> "> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[<masc-se:WhenRefTo="tns:Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ <masc-ex:BooleanExpressionRefTo=" tns:]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _BE"/> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[</masc-gp:GoalPolicyAssertion>]]> &#10;</xsl:text>        
                     
    </xsl:template>
    
    <!--       *********** UTILITY POLICY ASSERTION ********* -->
    <xsl:template match="MASCPolicyAssertions:UtilityPolicyAssertion" >   
             
        <xsl:comment> 
            DEFINITION OF EVENTS    
        </xsl:comment>                                     
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ <masc-se:EventDefinition MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"> "/> &#10; </xsl:text>                        
        
        <xsl:comment> 
            DEFINITION OF WHEN CONSTRUCTS   
        </xsl:comment>                                             
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-se:When MASCID="Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA["> ]]> &#10; </xsl:text>  
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:AllowedSates> ]]> &#10;</xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:SateRefTo="tns:Executing"/> ]]> &#10; </xsl:text>         
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:AllowedSates>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:EventRefTo="tns:]]></xsl:text><xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[</masc-se:When> ]]> &#10; </xsl:text>

        <xsl:comment> 
            DEFINITION OF ARITHMATIC EXPRESSIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes">&#10; <![CDATA[ <masc-ex:ArihmeticExpression MASCID= "]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _AE"/> &#10;</xsl:text>  
        <xsl:value-of disable-output-escaping="yes" select="//MASCPolicyAssertions:UtilityPolicyAssertion/@ArithmeticWithUnitExpression"/>  
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ </masc-ex:ArithmeticExpression> ]]> &#10; </xsl:text> 
        
        <xsl:comment> 
            DEFINITION OF UTILITY POLICY ASSERTIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-gp:GoalPolicyAssertion MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@MASCID"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text> 
        <xsl:text disable-output-escaping="yes"> <![CDATA[ BeneficiaryParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@BeneficiaryParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ PayingParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@PayingParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ ManagementParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@ManagementParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[IsActive="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@IsActive"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
          <!-- Is Tangible problem empty element -->
         <xsl:choose>                                      
         <xsl:when test="(count(//MASCPolicyAssertions:UtilityPolicyAssertion/IntangibleUtilities/text())=0)">
                <xsl:text disable-output-escaping="yes"> <![CDATA[IsTangible="true"/>]]></xsl:text> <xsl:text> &#10; </xsl:text>    
         </xsl:when>        
        <xsl:when test="not(//MASCPolicyAssertions:UtilityPolicyAssertion/IntangibleUtilities/text()='')">
                <xsl:text disable-output-escaping="yes"> <![CDATA[IsTangible="true"/>]]></xsl:text> <xsl:text> &#10; </xsl:text>    
            </xsl:when>            
            <xsl:otherwise>                
                    <xsl:text disable-output-escaping="yes"> <![CDATA[IsTangible="false"/>]]></xsl:text> <xsl:text> &#10; </xsl:text>    
                    <xsl:comment>
                        <xsl:text disable-output-escaping="yes">&#10;</xsl:text>
                        <xsl:apply-templates/>   
                        <xsl:text disable-output-escaping="yes">&#10;</xsl:text>
                    </xsl:comment>                                                                           
            </xsl:otherwise>        
        </xsl:choose>        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-se:WhenRefTo="tns:Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ <masc-ex:ArithmaticExpressionRefTo=" tns:]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:UtilityPolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _AE"/> &#10;</xsl:text>        
            <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[</masc-up:UtilityPolicyAssertion>]]> &#10;</xsl:text>                           
    </xsl:template>
    
    <!--  *********** META POLICY ASSERTION ********* -->
    <xsl:template match="MASCPolicyAssertions:MetaPolicyAssertion" >                   
        
        <xsl:comment> 
            DEFINITION OF EVENTS    
        </xsl:comment>                                       
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ <masc-se:EventDefinition MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"> "/> &#10; </xsl:text>                        
        
        <xsl:comment> 
            DEFINITION OF WHEN CONSTRUCTS   
        </xsl:comment>                                       
        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-se:When MASCID="Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA["> ]]> &#10; </xsl:text>  
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:AllowedSates> ]]> &#10;</xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:SateRefTo="tns:Executing"/> ]]> &#10; </xsl:text>         
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:AllowedSates>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"><![CDATA[ <masc-se:EventRefTo="tns:]]></xsl:text><xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/><xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>        
        <xsl:text disable-output-escaping="yes"><![CDATA[ </masc-se:PossibleTriggerEvents>]]> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[</masc-se:When> ]]> &#10; </xsl:text>
        
        <xsl:comment> 
            DEFINITION OF BOOLEAN EXPRESSIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes">&#10; <![CDATA[ <masc-ex:BooleanExpression MASCID= "]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _BE"/> &#10;</xsl:text>  
        <xsl:value-of disable-output-escaping="yes" select="//MASCPolicyAssertions:GoalpolicyAssertion/@BooleanExpression"/>  
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[ </masc-ex:BooleanExpression> ]]> &#10; </xsl:text> 
        
        <xsl:comment> 
            DEFINITION OF GOAL POLICY ASSERTIONS    
        </xsl:comment>             
        
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[<masc-gp:GoalPolicyAssertion MASCID="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text> 
        <xsl:text disable-output-escaping="yes"> <![CDATA[ ResponsibleParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@ResponsibleParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ ManagementParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@ManagementParty"/> <xsl:text disable-output-escaping="yes"> " &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ IsActiveResponsibleParty="]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@IsActive"/> <xsl:text disable-output-escaping="yes"> "> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[<masc-se:WhenRefTo="tns:Executing-]]></xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@When"/> <xsl:text disable-output-escaping="yes"><![CDATA[ "/> ]]> &#10; </xsl:text>
        <xsl:text disable-output-escaping="yes"> <![CDATA[ <masc-ex:BooleanExpressionRefTo=" tns:]]> </xsl:text> <xsl:value-of select="//MASCPolicyAssertions:GoalpolicyAssertion/@MASCID"/><xsl:text disable-output-escaping="yes"> _BE"/> &#10;</xsl:text>
        <xsl:text disable-output-escaping="yes"> &#10; <![CDATA[</masc-gp:GoalPolicyAssertion>]]> &#10;</xsl:text>        
        
    </xsl:template>
   </xsl:stylesheet>
    